a = int(input())
if 1000 <= a <= 9999:
    a1 = str(a//1000%10)
    a2 = str(a//100%10)
    a3 = str(a//10%10)
    a4 = str(a//1%10)
    spis = [int(a1), int(a2), int(a3), int(a4), int(a1 + a2), int(a2 + a3), int(a3 + a4), int (a1 + a2 + a3), int(a2 + a3 + a4), int(a1 + a2 + a3 + a4)]
    spis.sort()
    spis = spis[::-1]
    for x in spis:
        F = True
        for a in range(2, x//2 +1):
           if x%a ==0:
                F = False
                break
        if F == True:
            print (x)
            break
    if F == False:
        print('0')
else: print('0')
